<template>
  <div class="tab-bar-item" @click="item_click">
    <div v-if="!isActive">
      <slot name="item_icon"></slot>
    </div>
    <div v-else>
      <slot name="item_icon_active"></slot>
    </div>
    <div :style="activeStyle" >
      <slot name="item_text"></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  props: {
    path: String
  },
  data() {
    return {};
  },
  computed: {
    isActive() {
      return this.$route.path.indexOf(this.path) !==-1
    },
    activeStyle(){
      return this.isActive ? {color:'red'} :{}
    }
  },
  methods: {
    item_click() {
      console.log(this.path)
      this.$router.push(this.path);
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.tab-bar-item{
  flex: 1;
  text-align: center;
  height: 49px;
  font-size: 12px;
}
.tab-bar-item img{
  margin-top: 5px;
  width: 24px;
  height: 24px;
}
</style>
